define(["app"], function (app) {
    var deps = ["$http", "BaseService"];

    function resource($http, BaseService) {
        return initInfoAccountResource($http, BaseService.restfulUrl + "channel/", BaseService.formHeader);
    }

    function initInfoAccountResource($http, url, formHeader) {

        var headers = {
            "Content-Type" : "application/x-www-form-urlencoded;charset=utf-8"
        };

        return {
            uploadCropImage: function (formData, cropParam) {
                return $http.post("restful/fileUploadController/saveGroupPic?" + $.param(cropParam), formData, {
                    transformRequest: angular.identity,
                    headers: {
                        "Content-Type": undefined
                    }
                });
            },

            uploadImage: function (formData) {
                return $http.post("restful/fileUploadController/attachsUpload", formData, {
                    transformRequest: angular.identity,
                    headers: {
                        "Content-Type": undefined
                    }
                });
            },

            saveChannel: function (account) {
                return $http.post(url + "saveOrUpdateChannel", angular.toJson(account));
            },

            getChannel: function (channelId) {
                return $http.get(url + "queryChannelById", {
                    params: {
                        groupId: channelId
                    }
                });
            },

            getChannels: function (pageNo, pageSize) {
                return $http.get(url + "queryChannelList", {
                    params: {
                        pageNo: pageNo,
                        pageSize: pageSize
                    }
                });
            },

            updateStatus: function(channelId, status) {
                return $http.get(url + 'updateChannelStatus', {
                    params: {
                        groupId: channelId,
                        status: status
                    }
                });
            },

            removeChannel: function(channelId) {
                return $http.get(url + 'delChannel', {
                    params: {
                        groupId: channelId
                    }
                });
            },

            getSimpleChannels: function () {
                return $http.get(url + "queryChannelListMobile");
            },

            saveChannelItem: function (channelItem) {
                return $http.post(url + "saveChannelItem", angular.toJson(channelItem));
            },

            getChannelItem: function (channelItemId) {
                return $http.get(url + "queryChannelItemById", {
                    params: {
                        topicItiemId: channelItemId,
                        queryType:1
                    }
                });
            },

            getChannelItems: function (channelId, pageNo, pageSize,searchKey) {
                return $http.get(url + "queryChannelItemDetail", {
                    params: {
                        groupId: channelId,
                        queryType:1,
                        pageNo: pageNo,
                        pageSize: pageSize,
                        title:searchKey,
                        orderType:1
                    }
                });
            },

            removeChannelItem: function(channelItemId) {
                return $http.get(url + 'delChannelItem', {
                    params: {
                        topicItiemId: channelItemId
                    }
                });
            },

            queryChannelItemComment:function(channelItemId, pageNo, pageSize,commentTime){
                return $http.post(url + "queryChannelItemComment", {
                    topicItemId: channelItemId,
                    pageNo: pageNo,
                    pageSize: pageSize,
                    commentTime:commentTime
                }, {
                    headers: headers
                });
            },

            channelItemComment:function(channelItemCommentVo){
                return $http.post(url + "channelItemComment", angular.toJson(channelItemCommentVo));
            },

            setChannelItemPraise:function(channelItemId){
                return $http.get(url + 'setChannelItemPraise', {
                    params: {
                        topicItiemId: channelItemId
                    }
                });
            },

            searchAtUserByName:function(groupId,searchKey,pageNo,pageSize){
                return $http.post(url + "searchAtUserByName", {
                    groupId: groupId,
                    name: searchKey,
                    pageNo: pageNo,
                    pageSize: pageSize
                }, {
                    headers: headers
                });
            }
        };
    }

    resource.$inject = deps;
    app.lazy.factory("ChannelResource", resource);
});
